package com.banmao.dockertest.controller;

import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.websocket.server.PathParam;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@RestController
@RequestMapping("/index")
public class IndexController {

    @RequestMapping("/hello")
    public String hello(String name) {

        if(!StringUtils.hasText(name)) {
            name = "未知用户";
        }
        StringBuffer stringBuffer = new StringBuffer();
        LocalDateTime now = LocalDateTime.now();
        String format = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        System.out.println(format);
        stringBuffer.append("/hello 你好").append(" ").append(name).append(" ").append(format);

        return stringBuffer.toString();

    }

    @RequestMapping("/hello/{name}")
    public String helloName(@PathVariable("name") String name) {

        StringBuffer stringBuffer = new StringBuffer();
        LocalDateTime now = LocalDateTime.now();
        String format = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        System.out.println(format);
        stringBuffer.append("/hello/{name} 你好").append(" ").append(name).append(" ").append(format);

        return stringBuffer.toString();
    }

}
